home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / vfork.cpp < prev    next >
Text File  |  1991-11-11  |  1KB  |  53 lines

  1. |
  2. | vfork for MiNT. Note that the return address must be popped off the stack,
  3. | or else it could be clobbered by the child and the parent would be left
  4. | returning to la-la land. Also note that MiNT guarantees that register a1
  5. | will be preserved across a vfork() system call.
  6. |
  7.     .globl    _vfork
  8.     .globl    ___mint        | MiNT version kept here
  9.     .lcomm    L_vfsav, 128
  10.     .text
  11.     .even
  12. _vfork:
  13.     movel    sp@+, a1    | save return address; this is important!
  14. #ifdef __MSHORT__
  15.     tstw    ___mint
  16. #else
  17.     tstl    ___mint
  18. #endif
  19.     beq    L_TOS        | go do the TOS thing
  20.     movew    #0x113, sp@-    | push MiNT Pvfork() parameter
  21.     trap    #1        | Vfork
  22.     addql    #2, sp
  23.     tstl    d0        | error??
  24.     bmi    L_err
  25.     jmp    a1@        | return
  26. L_TOS:
  27.     moveml    d2-d7/a1-a6, L_vfsav    | save registers
  28.     pea    L_vfsav
  29.     pea    L_newprog
  30.     jsr    _tfork        | tfork(L_newprog, L_vfsav)
  31.     addl    #8, sp
  32.     moveml    L_vfsav, d2-d7/a1-a6    | restore reggies
  33.     tstl    d0        | fork went OK??
  34.     bmi    L_err        | no -- error
  35.     jmp    a1@        | return to caller
  36. L_err:
  37.     negl    d0
  38.     movel    d0, _errno    | save error code in errno
  39.     moveql    #-1, d0        | return -1
  40.     jmp    a1@        | return
  41.  
  42. |
  43. | L_newprog: here is where the child starts executing, with argument
  44. | L_vfsav. We restore registers, zero d0, and jump back to parent
  45. |
  46.  
  47. L_newprog:
  48.     addql    #4, sp        | pop useless return address
  49.     movel    sp@+, a0    | get address of save area
  50.     moveml    a0@, d2-d7/a1-a6    | restore reggies
  51.     clrl    d0        | child always returns 0 from vfork
  52.     jmp    a1@        | back to caller, as child process
  53.